﻿
@{
    ViewBag.Title = "Form";
    Layout = "~/Views/Shared/_Form.cshtml";
}
<style type="text/css">
    .topPanel .search .input-group .form-control {
        padding: 4px 5px !important;
        height: 22px !important;
        margin: 0 10px !important;
        width: 80%;
    }

    .zdyPanel {
        height: 50px;
        line-height: 50px;
        background-color: #fff;
        border-top: 1px solid #ddd;
        border-left: 1px solid #ddd;
        border-right: 1px solid #ddd;
        margin: 0px;
        float: left;
        width: 100%;
    }

    .zdyTool {
        float: left;
        padding-left: 10px;
        width: 100%;
    }

    .zdyBar {
        height: 50px;
        line-height: 50px;
        padding: 0px;
        width: 100px;
        margin: 0px;
    }

    .trBj {
        background-color: #f5f5f5;
    }

    .trSelectBj {
        background-color: #fff6e5;
    }

    .MyMenu {
        width: 100px;
        height: 100px;
        background-color: #f5f5f5;
    }

    .zdyUL {
        list-style-type: none;
        margin: 0px;
        padding: 0px;
    }

        .zdyUL li {
            float: left;
            list-style: none;
            height: 20px;
            line-height: 20px;
        }

            .zdyUL li a {
                cursor: pointer;
                padding: 5px 10px;
                border-radius: 4px;
                color: #337ab7;
            }

            .zdyUL li i {
                margin-right: 4px;
                font-size: 13px;
                color: #666;
                vertical-align: middle;
                margin-top: -1px;
            }

            .zdyUL li a:hover {
                text-decoration: none;
                background-color: #1ABC9C;
                color: #fff;
            }

    .form-control {
        height: 20px;
        line-height: 20px;
        padding: 0px;
        border-radius: 2px;
    }

    .table > tbody > tr > td, .table > tbody > tr > th, .table > tfoot > tr > td, .table > tfoot > tr > th, .table > thead > tr > td, .table > thead > tr > th {
        padding: 3px;
    }
</style>
<script>
    //var itemList = getCache("TypeList");
    $(function () {
        if ($.request("orderF_State") == "1") {
            $("#btn_Return").hide();
            $("#btn_UsingCheck").hide();
        }
        GetItemsJson();
        InitData();
    });

    function Dicts(type, value) {
        if (type == "sshy") {
            for (var i = 0; i < resultData.sshy.length; i++) {
                if (value == resultData.sshy[i]["F_ItemCode"]) {
                    return resultData.sshy[i]["F_ItemName"];
                }
            }
        } else if (type == "hdlx") {
            for (var i = 0; i < resultData.hdlx.length; i++) {
                if (value == resultData.hdlx[i]["F_ItemCode"]) {
                    return resultData.hdlx[i]["F_ItemName"];
                }
            }
        } else if (type == "city") {
            var citys = value.split(',');
            var html = "";
            for (var i = 0; i < resultData.City.length; i++) {
                for (var j = 0; j < citys.length; j++) {
                    if (citys.length == 1) {
                        if (citys[j] == resultData.City[i]["F_EnCode"]) {
                            html += resultData.City[i]["F_FullName"];
                        }
                    } else {
                        if (j == citys.length - 1) {
                            if (citys[j] == resultData.City[i]["F_EnCode"]) {
                                html += resultData.City[i]["F_FullName"];
                            }
                        } else {
                            if (citys[j] == resultData.City[i]["F_EnCode"]) {
                                html += resultData.City[i]["F_FullName"] + ',';
                            }
                        }
                    }
                }
            }
            return html;
        }
    }

    var resultData = {};
    function GetItemsJson() {
        resultData = getCache("CHECK_USING");
        if (!resultData || resultData.length <= 0) {
            $.ajax({
                url: "/CheckManager/CheckInfos/GetUsingDictionaryItemsJson",
                dataType: "json",
                async: false,
                success: function (data) {
                    resultData = data;
                    setCache("CHECK_USING", data);
                }, error: function (XMLHttpRequest, textStatus, errorThrown) {
                }
            });
        }
    }

    function InitData() {
        var F_CheckId = $.request("F_Id");
        var F_OrderId = $.request("F_OrderId");
        $.ajax({
            url: "/CheckManager/CheckInfos/GetOrderUsing?F_CheckId=" + F_CheckId + "&F_OrderId=" + F_OrderId + "",
            dataType: "json",
            async: false,
            success: function (data) {
                if (data != null) {
                    if (data.usingDemand != null) {


                        var SiteName = "";
                        var SupplierName = "";
                        for (var i = 0; i < data.usingDemand.length; i++) {
                            if (i == 0) {
                                $("#F_ActivityTheme").html(data.usingDemand[i].F_ActivityTheme);
                                $("#F_OrderId").html(data.usingDemand[i].F_Id);
                                $("#F_ActivityDate").html(data.usingDemand[i].F_ActivityStartDate + "至" + data.usingDemand[i].F_ActivityEndDate);
                                $("#F_ActivityCity").html(Dicts("city", data.usingDemand[i].F_ActivityCityId));
                                $("#F_CompanyName").html(data.usingDemand[i].F_ClientName);
                                $("#F_Brand").html(data.usingDemand[i].F_BrandName);
                                $("#F_IndustryType").html(Dicts("sshy", data.usingDemand[i].F_IndustryId));
                                $("#F_ActivityType").html(Dicts("hdlx", data.usingDemand[i].F_ActivityType));
                            }
                            if (i == data.usingDemand.length - 1) {
                                SiteName += data.usingDemand[i].SiteName;
                                SupplierName += data.usingDemand[i].SupplierName;
                            } else {
                                if (data.usingDemand[i].SiteName != "") {
                                    SiteName += data.usingDemand[i].SiteName + ",";
                                }

                                if (data.usingDemand[i].SupplierName != "") {
                                    SupplierName += data.usingDemand[i].SupplierName + ",";
                                }
                            }
                        }
                        $("#F_ActivitySite").html(SiteName);
                        $("#F_SiteCompany").html(SupplierName);
                    }

                    var count = 0;
                    var zccash = 0;
                    var sjcash = 0;
                    var sjlrcash = 0;
                    var hjcash = 0;
                    for (var i = 0; i < data.usingBusniess.length; i++) {
                        if (data.usingBusniess[i]["F_FeeType"] != 0) {
                            count = count + 1;
                            zccash = zccash + data.usingBusniess[i]["F_SpendCash"];
                            sjcash = sjcash + data.usingBusniess[i]["F_Tax"];
                            sjlrcash = sjlrcash + data.usingBusniess[i]["F_AfterTaxProfit"];
                            hjcash = hjcash + data.usingBusniess[i]["F_IncomeCash"];
                        }
                    }
                    $("#sp_intotal").html(hjcash);
                    $("#sp_outtotal").html(zccash);
                    $("#sp_taxtotal").html(sjcash);
                    $("#sp_taxProfittotal").html(sjlrcash);
                    $("#sp_ProfitMargintotal").html((parseInt(sjlrcash / hjcash * 10000) / 100).toString() + "%");
                    var newRow;
                    for (var i = 0; i < data.usingBusniess.length; i++) {
                        var F_IncomeCash =data.usingBusniess[i].F_IncomeCash;
                        newRow += "<tr>"
                        if (data.usingBusniess[i]["F_FeeType"] == 1) {
                            if (i == 0) {
                                var num = Number(data.usingBusniess.length) - 1;
                                newRow += "<td style=\"text-align:center;\">" + FeeName(data.usingBusniess[i]["F_FeeType"]) + "</td>";
                                newRow += "<td style=\"text-align:right;vertical-align:middle;\">" + data.usingBusniess[i]["F_IncomeCash"] + "</td>";
                                newRow += "<td style=\"text-align:center;\">" + data.usingBusniess[i]["F_FeeName"] + "</td>";
                                newRow += "<td style=\"text-align:right;\">" + data.usingBusniess[i]["F_SpendCash"] + "</td>";

                                newRow += "<td rowspan=\"" + data.usingBusniess.length + "\" style=\"text-align:right;vertical-align:middle;\">" + sjcash + "</td>";
                                newRow += "<td rowspan=\"" + data.usingBusniess.length + "\" style=\"text-align:right;vertical-align:middle;\">" + sjlrcash + "</td>";
                                newRow += "<td rowspan=\"" + data.usingBusniess.length + "\" style=\"text-align:right;vertical-align:middle;\"></td>";
                            } else {
                                newRow += "<td style=\"text-align:center;\">" + FeeName(data.usingBusniess[i]["F_FeeType"]) + "</td>";
                                newRow += "<td style=\"text-align:right;vertical-align:middle;\">" + data.usingBusniess[i]["F_IncomeCash"] + "</td>";
                                newRow += "<td style=\"text-align:center;\">" + data.usingBusniess[i]["F_FeeName"] + "</td>";
                                newRow += "<td style=\"text-align:right;\">" + data.usingBusniess[i]["F_SpendCash"] + "</td>";
                            }
                        } else {
                            newRow += "<td style=\"text-align:center;\">" + FeeName(data.usingBusniess[i]["F_FeeType"]) + "</td>";
                            newRow += "<td style=\"text-align:right;vertical-align:middle;\">" + data.usingBusniess[i]["F_IncomeCash"] + "</td>";
                            newRow += "<td style=\"text-align:center;\">" + data.usingBusniess[i]["F_FeeName"] + "</td>";
                            newRow += "<td style=\"text-align:right;\">" + data.usingBusniess[i]["F_SpendCash"] + "</td>";
                        }
                        newRow += "</tr>";
                    }

                    $("#newTable").append(newRow);

                    var inCount = 1;
                    var outCount = 1;
                    for (var i = 0; i < data.usingPrices.length; i++) {
                        if (data.usingPrices[i]["F_InOutType"] == 0) {
                            var newRow = "<tr>";
                            newRow += "<td style=\"text-align:center;\">第" + inCount + "笔收款</td>";
                            newRow += "<td style=\"text-align:right;\">" + formatDate(new Date(data.usingPrices[i]["F_InOutDate"])) + "</td>";
                            newRow += "<td style=\"text-align:center;\">金额</td>";
                            newRow += "<td style=\"text-align:right;\">" + data.usingPrices[i]["F_InOutCash"] + "</td>";
                            newRow += "<td style=\"text-align:right;\">" + data.usingPrices[i]["F_Remark"] + "</td>";
                            newRow += "<td style=\"text-align:center;\">开票日期</td>";
                            newRow += "<td style=\"text-align:right;\">" + formatDate(new Date(data.usingPrices[i]["F_InvoiceDate"])) + "</td>";
                            newRow += "</tr>";
                            inCount = inCount + 1;
                            $("#inTable").append(newRow);
                        } else if (data.usingPrices[i]["F_InOutType"] == 1) {
                            var newRow = "<tr>";
                            newRow += "<td style=\"text-align:center;\">第" + outCount + "笔支付</td>";
                            newRow += "<td style=\"text-align:right;\">" + formatDate(new Date(data.usingPrices[i]["F_InOutDate"])) + "</td>";
                            newRow += "<td style=\"text-align:center;\">金额</td>";
                            newRow += "<td style=\"text-align:right;\">" + data.usingPrices[i]["F_InOutCash"] + "</td>";
                            newRow += "<td style=\"text-align:center;\">收票日期</td>";
                            newRow += "<td style=\"text-align:right;\">" + formatDate(new Date(data.usingPrices[i]["F_InvoiceDate"])) + "</td>";
                            newRow += "</tr>";
                            outCount = outCount + 1;
                            $("#outTable").append(newRow);
                        } else if (data.usingPrices[i]["F_InOutType"] == 2) {
                            var newRow = "<tr>";
                            newRow += "<td style=\"text-align:center;\" colspan=\"2\">预定金</td>";
                            newRow += "<td style=\"text-align:center;\">金额</td>";
                            newRow += "<td style=\"text-align:right;\">" + data.usingPrices[i]["F_InOutCash"] + "</td>";
                            newRow += "<td></td>";
                            newRow += "<td style=\"text-align:center;\">收款日期</td>";
                            newRow += "<td style=\"text-align:right;\">" + formatDate(new Date(data.usingPrices[i]["F_InOutDate"])) + "</td>";
                            newRow += "</tr>";
                            $("#inTable").append(newRow);
                        } else if (data.usingPrices[i]["F_InOutType"] == 3) {
                            var newRow = "<tr>";
                            newRow += "<td style=\"text-align:center;\" colspan=\"2\">押金</td>";
                            newRow += "<td style=\"text-align:center;\">金额</td>";
                            newRow += "<td style=\"text-align:right;\">" + data.usingPrices[i]["F_InOutCash"] + "</td>";
                            newRow += "<td style=\"text-align:center;\">支付日期</td>";
                            newRow += "<td style=\"text-align:right;\">" + formatDate(new Date(data.usingPrices[i]["F_InOutDate"])) + "</td>";
                            newRow += "</tr>";
                            $("#outTable").append(newRow);
                        }
                    }

                    var signRow = [];
                    var len = data.signRecord.length;
                    for (var i = 0; i < len; i++) {
                        var signModel = data.signRecord[i];
                        signRow.push("<tr>");
                        signRow.push("<td style=\"text-align:center;\">" + signModel.signname + "</td>");
                        signRow.push("<td style=\"text-align:center;\">" + signModel.signorganize + "</td>");
                        signRow.push("<td style=\"text-align:center;\">" + signModel.F_Note + "</td>");
                        signRow.push("</tr>");
                    }
                    $("#signTable tbody").append(signRow.join(""));
                }
            }, error: function (XMLHttpRequest, textStatus, errorThrown) {
            }
        });
    }
    
    function FeeName(type) {
        if (type == 100) {
            return "管理服务费";
        }
        for (var i = 0; i < resultData.fylm.length; i++) {
            if (type == resultData.fylm[i].F_ItemCode) {
                return resultData.fylm[i].F_ItemName;
            }
        }
    }

    var formatDate = function (date) {
        var y = date.getFullYear();
        var m = date.getMonth() + 1;
        m = m < 10 ? '0' + m : m;
        var d = date.getDate();
        d = d < 10 ? ('0' + d) : d;
        return y + '-' + m + '-' + d;
    };

    
</script>
<form>
    
    <div style="padding-top: 5px;">
        <table class="form ui-jqgrid-htable ui-common-table table table-bordered">
            <tr class="ui-jqgrid-labels">
                <td class="formTitle">活动名称</td>
                <td class="formValue" colspan="3"><span id="F_ActivityTheme"></span></td>
                <td class="formTitle">订单号</td>
                <td class="formValue" colspan="3"><span id="F_OrderId"></span></td>
            </tr>
            <tr class="ui-jqgrid-labels">
                <td class="formTitle">活动时间</td>
                <td class="formValue" colspan="3"><span id="F_ActivityDate"></span></td>
                <td class="formTitle">活动场地</td>
                <td class="formValue" colspan="1"><span id="F_ActivitySite"></span></td>
                <td class="formTitle">城市</td>
                <td class="formValue"><span id="F_ActivityCity"></span></td>
            </tr>
            <tr class="ui-jqgrid-labels">
                <td class="formTitle">客户公司名称</td>
                <td class="formValue" colspan="3"><span id="F_CompanyName"></span></td>
                <td class="formTitle">场地公司名称</td>
                <td class="formValue" colspan="3"><span id="F_SiteCompany"></span></td>
            </tr>
            <tr class="ui-jqgrid-labels">
                <td class="formTitle">所属品牌</td>
                <td class="formValue"><span id="F_Brand"></span></td>
                <td class="formTitle">行业类型</td>
                <td class="formValue"><span id="F_IndustryType"></span></td>
                <td class="formTitle">产品线</td>
                <td class="formValue" colspan="3"><span id="F_ActivityType"></span></td>
            </tr>
        </table>
        <table class="form ui-jqgrid-htable ui-common-table table table-bordered" id="newTable">
            <thead>
                <tr class="ui-jqgrid-labels">
                    <th class="ui-th-column ui-th-ltr" style="text-align:center;">费用项目</th>
                    <th class="ui-th-column ui-th-ltr" style="text-align:center;">收入金额</th>
                    <th class="ui-th-column ui-th-ltr" style="text-align:center;">公司名称(供应商)</th>
                    <th class="ui-th-column ui-th-ltr" style="text-align:center;">支出金额</th>
                    <th class="ui-th-column ui-th-ltr" style="text-align:center;">税金</th>
                    <th class="ui-th-column ui-th-ltr" style="text-align:center;">税后利润</th>
                    <th class="ui-th-column ui-th-ltr" style="text-align:center;">利润率</th>
                </tr>
            </thead>
            <tbody></tbody>
            <tfoot>
                <tr>
                    <td style="text-align:center;">合计</td>
                    <td style="text-align:right;"><span id="sp_intotal"></span></td>
                    <td></td>
                    <td style="text-align:right;"><span id="sp_outtotal"></span></td>
                    <td style="text-align:right;"><span id="sp_taxtotal"></span></td>
                    <td style="text-align:right;"><span id="sp_taxProfittotal"></span></td>
                    <td style="text-align:right;"><span id="sp_ProfitMargintotal"></span></td>
                </tr>
            </tfoot>
        </table>
        <table class="form ui-jqgrid-htable ui-common-table table">
            <tr>
                <td>
                    <table class="form ui-jqgrid-htable ui-common-table table table-bordered" id="inTable"></table>
                </td>
                <td>
                    <table class="form ui-jqgrid-htable ui-common-table table table-bordered" id="outTable"></table>
                </td>
            </tr>
        </table>
        <table class="form ui-jqgrid-htable ui-common-table table table-bordered" id="signTable" style="margin-top:20px;">
            <thead>
                <tr class="ui-jqgrid-labels">
                    <th class="ui-th-column ui-th-ltr" style="text-align:center;" width="15%">会签人</th>
                    <th class="ui-th-column ui-th-ltr" style="text-align:center;" width="15%">会签部门</th>
                    <th class="ui-th-column ui-th-ltr" style="text-align:center;">会签内容</th>
                </tr>
            </thead>
            <tbody></tbody>
        </table>
    </div>
</form>

